package com.kantboot.business.water.repository;

import com.kantboot.business.water.domain.dto.BusWaterGoodsDTOInClient;
import com.kantboot.business.water.domain.entity.BusWaterGoods;
import com.kantboot.business.water.domain.vo.BusWaterGoodsVOInClient;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface BusWaterGoodsVOInClientRepository extends JpaRepository<BusWaterGoodsVOInClient,Long> {


    @Query("""
            FROM BusWaterGoodsVOInClient
            WHERE (:#{#param.keyword} IS NULL OR :#{#param.keyword} = '' OR name LIKE CONCAT('%',:#{#param.keyword},'%')
            OR description LIKE CONCAT('%',:#{#param.keyword},'%'))
            AND isDeleted = false 
            AND (:#{#param.isShowInVip} IS NULL OR isShowInVip = :#{#param.isShowInVip})
            AND (:#{#param.isShowInUser} IS NULL OR isShowInUser = :#{#param.isShowInUser})
            AND (:#{#param.salePriceMin} IS NULL OR salePrice >= :#{#param.salePriceMin})
            AND (:#{#param.salePriceMax} IS NULL OR salePrice <= :#{#param.salePriceMax})
            """
            + "AND statusCode = '"+ BusWaterGoods.STATUS_CODE_SELLING+"'"
    )
    Page<BusWaterGoodsVOInClient> getBodyDataClient(
            @Param("param") BusWaterGoodsDTOInClient param,
            Pageable pageable
    );

}
